package FlowGram.Application.CommandHost.FinchActionListeners;

import java.awt.event.ActionEvent;
import java.util.Collection;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import FlowGram.Application.Parser.Actions.FunctionInvocation;
import FlowGram.Application.Parser.Actions.Control.FunctionDefinition;
import FlowGram.Application.Parser.Actions.Control.If;
import FlowGram.Application.Parser.Actions.Property.IsBlocked;
import FlowGram.Application.Parser.Actions.Property.IsNotBlocked;
import FlowGram.Application.Parser.Utility.ClassFinder;

public class FunctionInvocationListener extends FinchActionListener {

	JFrame frame;
	
	FunctionInvocation fInvAction;
	
	public FunctionInvocationListener(JFrame frame){
		this.frame = frame;
		fInvAction = new FunctionInvocation();
	}
	
	
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		Collection<String> fd = FunctionDefinition.getAllFunctionNames();
		
		
		String funcName = (String)JOptionPane.showInputDialog(
		                    frame,
		                    "Select function to invoke:\n",
		                    "Function Invocation",
		                    JOptionPane.INFORMATION_MESSAGE,
		                    null,
		                    fd.toArray(),
		                    "Select Function");
		if(funcName != null){
			fInvAction.setDefinition(FunctionDefinition.findFunction(funcName));
			addCode(fInvAction);
		}
		
	}
}
